/**
 * 加密解密
 */
const JWT = require("jsonwebtoken");
const key = process.env.JWT_KEY;

const authcode = function (str, operation) {
    operation ? operation : 'DECODE';
    if (operation == 'DECODE') {
        /* 解密 */
        return JWT.verify(str, key);
    } else {
        /**加密 */
        return JWT.sign({ str }, key, {
            expiresIn: "30d"
        });
    }
}

module.exports = authcode;